package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.Building;
import com.woniuxy.service.BuildingService;
import com.woniuxy.util.PageData;
import com.woniuxy.util.RespongseData;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/building")
public class BuildingController {
    @Resource
    private BuildingService buildingService;

    @GetMapping("/buildingPage")
    public String userPage(){
        return "building/building";
    }

    @GetMapping("/queryBuild")
    @ResponseBody
    public RespongseData queryBuild(){
        List<Building> buildings = buildingService.queryBuilding();
        return new RespongseData(200,"ok",buildings);
    }


    @PostMapping("/queryBuildByNum")
    @ResponseBody
    public RespongseData queryBuildByNum(@RequestBody PageData<Building> pageData){
        PageInfo<Building> buildingPageInfo = buildingService.queryBuildingByNum(pageData);
        return new RespongseData(200,"ok",buildingPageInfo);
    }

    @PostMapping("/addBuild")
    @ResponseBody
    public RespongseData addBuild(@RequestBody Building building){
        buildingService.addBuild(building);
        return new RespongseData(200,"ok",null);
    }

    @PostMapping("/batchDelBuild")
    @ResponseBody
    public RespongseData batchDelBuild(@RequestBody List<Integer> ids){
        buildingService.batchDelBuild(ids);
        return new RespongseData(200,"ok",null);
    }

    @GetMapping("/selectBuildById/{id}")
    @ResponseBody
    public RespongseData selectBuildById(@PathVariable("id") Integer id){
        Building building = buildingService.selectBulidById(id);
        return new RespongseData(200,"ok",building);
    }

    @PostMapping("/saveupdateBuild")
    @ResponseBody
    public RespongseData saveupdateBuild(@RequestBody Building building){
        buildingService.saveupdateBuild(building);
        return new RespongseData(200,"ok",null);
    }

    @GetMapping("/saveDelBuild/{delId}")
    @ResponseBody
    public RespongseData saveDelBuild(@PathVariable("delId") Integer id){
        buildingService.saveDelBuild(id);
        return  new RespongseData(200,"ok",null);
    }

}
